<?php
if (isset($_POST['submit'])) {
	if ($m == 1) {
	// magento
	$qty = $_POST['qty'];
	$arrProducts = array(
			array(
				"product_id" => "$pid",
				"qty" => $qty
			)
		);
	try {
		$cid = $_SESSION['cid'];
		$resultCartProductAdd = $soap->call($session_id, "cart_product.add", array($cid, $arrProducts));
	} catch (Exception $e) {
		$cid = $soap->call ($session_id, 'cart.create');
		$_SESSION['cid'] = $cid;
		$resultCartProductAdd = $soap->call($session_id, "cart_product.add", array($cid, $arrProducts));
	}
	header("location: cart.php");
	} else {
	// our own db
		include 'ecstore_v1_config.php';
		include ($site_root . '/insp-modules/misc/config.php');
		$qty = $_POST['qty'];
		
		$conn = mysql_connect($host, $user, $password) or die(mysql_error());
		mysql_select_db("ecstore_nm_db");

		$sql_prod = "SELECT * FROM product WHERE ProdID = '$pid'";
		$result_prod = mysql_query($sql_prod, $conn) or die(mysql_error());

		$prod = mysql_fetch_assoc($result_prod);
		$prod_name = $prod['Name'];
		$prod_price = $prod['Price'];
		$prod_total = $prod_price * $qty;
		$arrProducts = array(
			"pid" => "$pid",
			"pname" => "$prod_name",
			"price" => "$prod_price",
			"qty" => $qty,
			"total" => $prod_total
		);
		$cart_array = $_SESSION['cart_array'];
		array_push($cart_array, $arrProducts);
		$_SESSION['cart_array'] = $cart_array;
		header("location: cart.php");
	}
}
?>